﻿using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Domain.Repositories;
using SingleUserMall.Common;
using SingleUserMall.StoreSettings.VO;
using System.Linq;
using System.Threading.Tasks;

namespace SingleUserMall.StoreSettings
{
    public class StoreSettingAppService : SingleUserMallAppServiceBase, IStoreSettingAppService
    {
        private readonly IRepository<StoreSetting, long> _storeSettingRepository;
        private readonly IRepository<AdvertSetting, long> _advertSettingRepository;
        public StoreSettingAppService(
            IRepository<StoreSetting, long> storeSettingRepository, IRepository<AdvertSetting, long> advertSettingRepository)
        {
            _storeSettingRepository = storeSettingRepository;
            _advertSettingRepository = advertSettingRepository;
        }

        public async Task<ListResultDto<AdvertSettingVO>> GetAdvertSettingsAsync()
        {
            var advertSettings = _advertSettingRepository.GetAll().OrderByDescending(x => x.CreationTime);
            return await advertSettings.ToListResultDtoAsync<AdvertSetting, AdvertSettingVO>();
        }

        public async Task<ListResultDto<StoreSettingVO>> GetStoreSettingsAsync()
        {
            var storeSettings = _storeSettingRepository.GetAll();
            return await storeSettings.ToListResultDtoAsync<StoreSetting, StoreSettingVO>();
        }
    }
}
